﻿using System;
using System.Web.UI.WebControls;
using Pyxis.FluentSelenium.SimpleWebApp.Forum.Domain;
using System.Linq;

namespace Pyxis.FluentSelenium.SimpleWebApp.Forum
{
    public partial class AllPosts : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
                LoadPosts();
        }

        private void LoadPosts()
        {
            grdPosts.DataSource = FakePersistance.Posts;
            grdPosts.DataBind();
        }

        protected void grdPosts_Sorting(object sender, GridViewSortEventArgs e)
        {
            if (e.SortExpression == "Author")
                grdPosts.DataSource = FakePersistance.Posts.OrderBy(p1 => p1.Author);
            else
                grdPosts.DataSource = FakePersistance.Posts.OrderBy(p1 => p1.Subject);

            grdPosts.DataBind();
        }
    }
}